package it.mbus.bz;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ProgressBar;

public class Starter extends Activity {

	static ProgressBar progressBar =null ;

	public static boolean inizialize() throws IOException {
		progressBar.setProgress(30);
		// Create Folder
		File folder = new File(Environment.getExternalStorageDirectory()
				.toString() + "/mBus");
		folder.mkdirs();
		progressBar.setProgress(50);
		// Save the path as a string value
		String extStorageDirectory = folder.toString();

		// Create New file and name it logU.mbs
		File file = new File(extStorageDirectory, "logU.mbs");
		progressBar.setProgress(70);
		return file.createNewFile();

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_starter);
		progressBar = (ProgressBar) findViewById(R.id.progressBar);

		/***
		 * 1) controllo se ci sono dati nella memoria 
		 * 	a) se si: controllo i dati
		 * 		a1) dati validi: mando a HOME 
		 * 		a2) dati errati: mando a Log/Reg
		 * 	b) se no: crea la cartella mBus, e mando a Log/Reg
		 * 2) controllo connessione internet
		 * 3) controllo NFC
		 * 4) controllo GPS
		 **/
		
		progressBar.setProgress(0);
		progressBar.setMax(100);
		progressBar.setProgress(20);
		try {
			progressBar.setProgress(80);
			if (inizialize()) {
				
				// NON ESISTE
				Intent reg = new Intent(this, LogReg.class);
				startActivity(reg);
				progressBar.setProgress(100);
				finish();
			} else {
				
				// FILE GIA PRESENTE
				// prendo i dati, li verifico e mando alla activty giusta
				progressBar.setProgress(100);
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//progressBar.setVisibility(View.GONE);


	}

}
